% !TEX program=xelatex

% nobabel means you'll need to provide your own month names, week day headings,
% etc
\documentclass[17pt,nobabel,sundayweek,giant]{cdcalendar}

%% and here we do some settings for a calendar in Chinese
%% (*not* the lunar calendar! Just localising the Gregorian calendar into
%% Chinese)
\usepackage{zh-mod}

\setmainfont[Ligatures=TeX,Numbers=Lining]{EB Garamond}
\setsansfont[Ligatures=TeX,BoldItalicFont=Fira Sans Italic,BoldFont=Fira Sans,Numbers=OldStyle]{Fira Sans Light}

\usepackage{csvsimple,xstring}

\robustify{\\}
\newcommand{\annotdate}[2]{%
	\ifboolexpr{ test{\IfBeginWith{#2}{初}}
						or test{\IfBeginWith{#2}{十}}
						or test{\IfEndWith{#2}{十}}
						or test{\IfBeginWith{#2}{廿}}
	}{\def\extra{}}
	 {\def\extra{red!70!black}}
	\node[font=\tiny\CJKspace,\extra,
	anchor=north,outer sep=0.55ex,text width=2.5em,align=flush center]
	at (cdCal-\thepage-#1) {#2};%
}

\newcommand{\importlunar}[1]{%
\begin{scope}[on background layer]%
  %% lunar-2019.csv contains mappings between the Chinese lunar calendar and
  %% 2019 Gregorian calendar, with columns EVENT and DATE.
  %% Sourced from https://github.com/infinet/lunar-calendar/blob/master/chinese_lunar_prev_year_next_year.ics; converted to Simplified Chinese;
  %% converted to .csv with https://www.indigoblue.eu/ics2csv/
  \csvreader[filter test=\IfBeginWith{\LNDATE}{#1}]
  {lunar-2019.csv}{EVENT=\LNEVENT,DATE=\LNDATE}
  {\annotdate{\LNDATE}{\LNEVENT}}
\end{scope}%
}

%%%%%%
% Some settings for the monthly calendars, to accomodate extra annotations below each date
%%%%%%
\dayHeadingStyle{font=\sffamily\color{gray!90}}
\sundayColor{red}
\monthTitleStyle{font={\fontsize{42pt}{44pt}\bfseries\sffamily\fangsong}, red!50!RedViolet}
\eventStyle{\scriptsize\songti}
\renewcommand\printeventname[1]{{\heiti #1}}
\tikzset{every calendar/.append style={day yshift=2.5\ccwd}}
\patchcmd{\monthCalendar}{0pt,\paperheight}{0pt,\dimexpr\paperheight-0.5cm\relax}{}{}

%% Define all event mark styles here
\tikzset{holiday/.style={rectangle,fill=orange!70}}
\tikzset{pink icon/.style={text=Pink,font=\large}}
\tikzset{blue icon/.style={text=SkyBlue,font=\large}}

\usepackage{fontawesome}
\usepackage{graphicx}
\usepackage{wallpaper}
\graphicspath{{img/}}

\setlength{\CalPageMargin}{1cm}
% \setlength{\EventLineWidth}{6in}
\geometry{a4paper}

\begin{document}

\TileWallPaper{.5\paperwidth}{.5\paperheight}{ricepaper_v3}
\coverImage[（元）景德镇窑蓝釉白龙戏珠纹盘。BabelStone摄，CC BY-SA 3.0. \url{ https://commons.wikimedia.org/w/index.php?curid=19011812}]
{Yuan_Jingdezhen_dragon_and_pearl_dish}

\coverTitle[
font=\fontsize{48pt}{50pt}\sffamily\fangsong\bfseries,
text width=\linewidth,align=flush right,red!50!RedViolet]
{2019年历（附农历节气）}

\makeCover

\clearpage
%% Uncomment the next line if you want to clear the background
%\ClearWallPaper

\illustration[西汉，错金银青铜锯齿形器。图片拍摄：一只饭包。@张博力\url{http://t.cn/EUm09h0}]{\textwidth}{IMG_4645}

\begin{monthCalendar}{2019}{01}
  \event[mark style=holiday]{2019-01-01}{}{元旦}
  \event{2019-01-18}{2019-01-20}{ACME Conference}
  \event[mark style=pink icon,marker=\faBirthdayCake]{2019-01-23}{}{朋友生日}
  \importlunar{2019-01}
\end{monthCalendar}

\clearpage

\illustration[商 有领玉璧 1986年广汉三星堆遗址K2出土 四川广汉三星堆博物馆藏 @川后 \url{http://t.cn/EUmH7He}]{\textwidth}{youlingyupi}

\begin{monthCalendar}{2019}{02}
  \importlunar{2019-02}
\end{monthCalendar}

\clearpage

\illustration[Immortals Riding Dragons: Section of a Tomb Pediment.
Han dynasty (206 B.C.--A.D. 220), 1st century B.C./A.D. Probably from Henan province, China. Art Initiative Chicago. \url{http://t.cn/EUmmVjV}]{\textwidth}{dragonriders}

\begin{monthCalendar}{2019}{03}
  \importlunar{2019-03}
\end{monthCalendar}

\clearpage

\illustration[西汉，错金银青铜锯齿形器。图片拍摄：一只饭包。@张博力\url{http://t.cn/EUm09h0}]{\textwidth}{IMG_4645}

\begin{monthCalendar}{2019}{04}
  \importlunar{2019-04}
\end{monthCalendar}

\clearpage

\illustration[商 有领玉璧 1986年广汉三星堆遗址K2出土 四川广汉三星堆博物馆藏 @川后 \url{http://t.cn/EUmH7He}]{\textwidth}{youlingyupi}

\begin{monthCalendar}{2019}{05}
  \importlunar{2019-05}
\end{monthCalendar}

\clearpage

\illustration[Immortals Riding Dragons: Section of a Tomb Pediment.
Han dynasty (206 B.C.--A.D. 220), 1st century B.C./A.D. Probably from Henan province, China. Art Initiative Chicago. \url{http://t.cn/EUmmVjV}]{\textwidth}{dragonriders}

\begin{monthCalendar}{2019}{06}
  \importlunar{2019-06}
\end{monthCalendar}

\clearpage

\illustration[西汉，错金银青铜锯齿形器。图片拍摄：一只饭包。@张博力\url{http://t.cn/EUm09h0}]{\textwidth}{IMG_4645}

\begin{monthCalendar}{2019}{07}
  \importlunar{2019-07}
\end{monthCalendar}

\clearpage

\illustration[商 有领玉璧 1986年广汉三星堆遗址K2出土 四川广汉三星堆博物馆藏 @川后 \url{http://t.cn/EUmH7He}]{\textwidth}{youlingyupi}

\begin{monthCalendar}{2019}{08}
  \importlunar{2019-08}
\end{monthCalendar}

\clearpage

\illustration[Immortals Riding Dragons: Section of a Tomb Pediment.
Han dynasty (206 B.C.--A.D. 220), 1st century B.C./A.D. Probably from Henan province, China. Art Initiative Chicago. \url{http://t.cn/EUmmVjV}]{\textwidth}{dragonriders}

\begin{monthCalendar}{2019}{09}
  \importlunar{2019-09}
\end{monthCalendar}

\clearpage

\illustration[西汉，错金银青铜锯齿形器。图片拍摄：一只饭包。@张博力\url{http://t.cn/EUm09h0}]{\textwidth}{IMG_4645}

\begin{monthCalendar}{2019}{10}
  \importlunar{2019-10}
\end{monthCalendar}

\clearpage

\illustration[商 有领玉璧 1986年广汉三星堆遗址K2出土 四川广汉三星堆博物馆藏 @川后 \url{http://t.cn/EUmH7He}]{\textwidth}{youlingyupi}

\begin{monthCalendar}{2019}{11}
  \importlunar{2019-11}
\end{monthCalendar}

\clearpage

\illustration[Immortals Riding Dragons: Section of a Tomb Pediment.
Han dynasty (206 B.C.--A.D. 220), 1st century B.C./A.D. Probably from Henan province, China. Art Initiative Chicago. \url{http://t.cn/EUmmVjV}]{\textwidth}{dragonriders}

\begin{monthCalendar}{2019}{12}
  \importlunar{2019-12}
\end{monthCalendar}

\end{document}
